﻿/* 
┏━━━━━━━━━━━＼／━━━━━━━━━━━┓      
┃┏━━━━━━━━━━━━━━━━━━━━━━┓┃
     ------------------------------------------    
       Author           : TengSea   
       Created          : Mouth-Day-Year                              
       Last Modified By : TengSea                                 
       Last Modified On : Mouth-Day-Year                                                               
       Description      : 
     __________________________________________
     Copyright (c) TengSea. All rights reserved.
 ┃┗━━━━━━━━━━━━━━━━━━━━━━┛┃                            
 ┗━━━━━━━━━∪━━━━∪━━━━━━━━━┛
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hhmocon.Mes.Application.Common
{
    static class ComputeMouth
    {
        /// <summary>
        /// 计算区间月份
        /// </summary>
        /// <param name="startYear">开始年</param>
        /// <param name="startMonth">开始月</param>
        /// <param name="endYear">结束年</param>
        /// <param name="endMonth">结束月</param>
        /// <returns></returns>
        public static List<string> ComputeMonth(int startYear, int startMonth, int endYear, int endMonth)
        {
            List<ComputeDate> ComputeDateList = new List<ComputeDate>();   //计算的区间结果存放在集合
            List<string> ymList = new List<string>();
            if (startYear <= endYear)
            {
                int ComputeYear = endYear - startYear;  //计算开始年和结束年差值
                if (ComputeYear > 0)//跨年情况
                {
                    //循环开始年到结束年
                    for (int i = startYear; i <= startYear + ComputeYear; i++)
                    {
                        if (i == endYear)
                        {
                            for (int lastYear = 1; lastYear <= endMonth; lastYear++)
                            {
                                ComputeDateList.Add(new ComputeDate() { Year = i, Month = lastYear });
                            }
                        }
                        else
                        {
                            if (i == startYear)
                            {
                                for (int lastMonth = startMonth; lastMonth <= 12; lastMonth++)
                                {

                                    ComputeDateList.Add(new ComputeDate() { Year = i, Month = lastMonth });
                                }
                            }
                            else
                            {
                                for (int quyue = 1; quyue <= 12; quyue++)
                                {
                                    ComputeDateList.Add(new ComputeDate() { Year = i, Month = quyue });
                                }
                            }
                        }
                    }
                }
                else
                {
                    //同年情况
                    for (int i = startMonth; i <= endMonth; i++)
                    {
                        ComputeDateList.Add(new ComputeDate() { Year = startYear, Month = i });
                    }
                }

                foreach (var item in ComputeDateList)
                {
                    //发现月份会少0，判断小于10月补0
                    var months = "";
                    if (item.Month < 10)
                    {
                        months = "0" + item.Month;
                    }
                    else
                    {
                        months = Convert.ToString(item.Month);
                    }
                    ymList.Add(item.Year + "-" + months);
                }
            }
            return ymList;
        }
    }
}
